// 菜品管理相关接口
import request from '@/utils/request'

/**
 * 菜品分页查询
 * @param {Object} params - 查询参数 {name, categoryId, status, page, pageSize}
 * @returns {Promise}
 */
export const getDishPage = (params) => {
  return request({
    url: '/admin/dish/page',
    method: 'get',
    params
  })
}

/**
 * 新增菜品
 * @param {Object} data - 菜品信息 {name, categoryId, price, image, description, status, flavors}
 * @returns {Promise}
 */
export const addDish = (data) => {
  return request({
    url: '/admin/dish',
    method: 'post',
    data
  })
}

/**
 * 修改菜品
 * @param {Object} data - 菜品信息 {id, name, categoryId, price, image, description, status, flavors}
 * @returns {Promise}
 */
export const updateDish = (data) => {
  return request({
    url: '/admin/dish',
    method: 'put',
    data
  })
}

/**
 * 批量删除菜品
 * @param {String} ids - 菜品id，多个id用逗号分隔
 * @returns {Promise}
 */
export const deleteDish = (ids) => {
  return request({
    url: '/admin/dish',
    method: 'delete',
    params: { ids }
  })
}

/**
 * 根据id查询菜品
 * @param {Number} id - 菜品id
 * @returns {Promise}
 */
export const getDishById = (id) => {
  return request({
    url: `/admin/dish/${id}`,
    method: 'get'
  })
}

/**
 * 根据分类id查询菜品
 * @param {Number} categoryId - 分类id
 * @returns {Promise}
 */
export const getDishList = (categoryId) => {
  return request({
    url: '/admin/dish/list',
    method: 'get',
    params: { categoryId }
  })
}

/**
 * 菜品起售、停售
 * @param {Number} id - 菜品id
 * @param {Number} status - 状态(1:起售, 0:停售)
 * @returns {Promise}
 */
export const updateDishStatus = (id, status) => {
  return request({
    url: `/admin/dish/status/${status}`,
    method: 'post',
    params: { id }
  })
}